import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserState = defineStore(
  'user',
  () => {
    // token令牌
    const token = ref('')
    //获取
    const getToken = () => {
      return token.value
    }
    //设置
    const setToken = (newValues) => {
      token.value = newValues
    }

    const username = ref('')
    const setUsername = (newUsername) => {
      username.value = newUsername
    }

    const clear = () => {
      token.value = ''
    }

    return {
      token,
      getToken,
      setToken,
      username,
      setUsername,
      clear
    }
  },
  {
    persist: true
  }
)
